package xyz.penghaonan.wificonnect;

import android.app.Notification;
import android.content.Context;
import android.net.wifi.WifiManager;

import androidx.annotation.NonNull;

import xyz.penghaonan.wificonnect.connect.BaseConnectHelper;
import xyz.penghaonan.wificonnect.connect.DeviceConnectHelper;
import xyz.penghaonan.wificonnect.connect.PhoneConnectHelper;
import xyz.penghaonan.wificonnect.message.IMsg;
import xyz.penghaonan.wificonnect.service.ServiceHelper;

public class WifiConnectSDK {
    private static Context context;
    private static WifiManager wifiManager;
    private static ServiceHelper serviceHelper;
    private static Config config;
    public static void init(@NonNull Context context, Config config) {
        WifiConnectSDK.context = context.getApplicationContext();
        WifiConnectSDK.config = config;
    }

    public static Context getContext() {
        return context;
    }

    public static WifiManager getWifiManager() {
        if (wifiManager == null) {
            wifiManager = (WifiManager) getContext().getApplicationContext().getSystemService(Context.WIFI_SERVICE);
        }
        return wifiManager;
    }

    public static ServiceHelper getServiceHelper() {
        if (serviceHelper == null) {
            serviceHelper = new ServiceHelper();
        }
        return serviceHelper;
    }

    public static Config getConfig() {
        return config;
    }

    abstract public static class Config {

        BaseConnectHelper connectHelper;

        public abstract Notification getServiceNotification();

        public abstract int getServiceNotificationId();

        public abstract void OnMsgReceived(IMsg msg);

        protected abstract boolean isPhone();

        public BaseConnectHelper getConnectHelper() {
            if (connectHelper == null) {
                if (isPhone()) {
                    connectHelper = new PhoneConnectHelper();
                }else {
                    connectHelper = new DeviceConnectHelper();
                }
            }
            return connectHelper;
        }
    }
}
